﻿using Fortunate.Common.Utility;
using Fortunate.Common.Extensions;

namespace Fortunate.Common.Global
{
    /// <summary>
    /// 目录配置
    /// </summary>
    public class DirectoryConfig
    {
        /// <summary>
        /// 存储路径
        /// </summary>
        public String StoragePath { get; set; }

        /// <summary>
        /// 文件大小
        /// </summary>
        public String FileMax { get; set; } = "10";

        /// <summary>
        /// 临时目录
        /// </summary>
        public String TempPath { get; set; }

        /// <summary>
        /// 获取主要存储路径
        /// </summary>
        /// <returns></returns>
        public String GetPath => String.Concat(AppDomain.CurrentDomain.BaseDirectory, this.StoragePath);

        /// <summary>
        /// 限制 （this.FileMax） M
        /// </summary>
        public long limitSiza
        {
            get
            {
                return Convert.ToInt32(this.FileMax) * 1024 * 1024;
            }
        }

        /// <summary>
        /// 获取临时目录
        /// </summary>
        /// <returns>临时目录</returns>
        public String GetTempPath()
        {
            var path = this.StoragePath + "\\" + this.TempPath;
            return path;
        }

        /// <summary>
        /// 清空临时目录
        /// </summary>
        public void CleanTempPath(string path)
        {
            FileContext.ClearDirectory(path + this.GetTempPath());
        }

        /// <summary>
        /// 获取业务附件目录
        /// </summary>
        /// <returns>业务附件目录</returns>
        public String GetBusinessAttachmentPath()
        {
            var path = this.StoragePath + "\\" + DateTime.Now.ToYear() + "\\";
            return path;
        }
    }
}
